#ifndef  __TERMINVERTER_H_
#define  __TERMINVERTER_H_

#include "common.h"
#include "globals.h"
#include "termlist.h"
#include "logger.h"
#include "shared_func.h"
#include <google/dense_hash_map>
#include "idxBuilder.h"

#define RET_NULL 3
#define RET_EOF  4

//5G
#define MAX_NODE_ALLOC	(5*1024*1024*1024)

//5M*sizeof(uint64_t)
#define TSIGN_ARR_NUM_INIT (5*1024*1024)

class TermInverter {
public:
    TermInverter() {};
    ~TermInverter() {};

    int load();
    int invert(char* in_fname, char* out_fname);
    void reset();
private:
    int process_one_link(FILE* ifp, FILE* ofp);
    int addTerm(tl_head_t* head, tl_term_t* term, offset_t* off);
    link_node *alloc_new_node();
    int serialize(FILE* fp);

private:
    uint64_t* tsign_arr;
    uint32_t  tsign_alloced;
    uint32_t  tsign_num;

    google::dense_hash_map<uint64_t , link_list>* tlink;
    uint64_t m_size_alloc;

private:
};

#endif  //__TERMINVERTER_H_
